/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.a1anwang.okble.demo.widget;

import ohos.agp.components.AttrSet;
import ohos.agp.components.ComponentContainer;
import ohos.app.Context;

public abstract class HeadBaseComponent extends ComponentContainer {


    public enum RefreshState {
        /**
         * 初始状态
         */
        STATE_INIT,
        /**
         * 下拉刷新的头部可见
         */
        STATE_VISIBLE,
        /**
         * 正在刷新的状态
         */
        STATE_REFRESH,
        /**
         * 超出可刷新距离的状态
         */
        STATE_OVER,
        /**
         * 超出刷新位置松开手后的状态
         */
        STATE_OVER_RELEASE
    }

    // 默认状态为  初始化状态
    protected RefreshState mState = RefreshState.STATE_INIT;
    /**
     * 触发下拉刷新时的最小高度，当刚好下拉到这个距离，那就直接刷新，
     * 如果下拉的距离超过了这个距离，那就先滚动到这个距离，然后才开始刷新
     */
    public int mPullRefreshHeight;
    /**
     * 最小阻尼，用户越往下拉，越不跟手
     */
    public float minDamp = 1.6f;
    /**
     * 最大阻尼
     */
    public float maxDamp = 2.2f;
    /**
     * HeadBaseComponent
     *
     * @param context context
     */
    public HeadBaseComponent(Context context) {
        this(context, null);
    }
    /**
     * HeadBaseComponent
     *
     * @param context context
     * @param attrSet attrSet
     */
    public HeadBaseComponent(Context context, AttrSet attrSet) {
        this(context, attrSet, "");
    }
    /**
     * HeadBaseComponent
     *
     * @param context context
     * @param attrSet attrSet
     * @param styleName styleName
     */
    public HeadBaseComponent(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init();
    }
    /**
     * init
     */
    public abstract void init();
    /**
     * onHeadVisible
     */
    public abstract void onHeadVisible();
    /**
     * onHeadOver
     */
    public abstract void onHeadOver();
    /**
     * onRefresh
     */
    public abstract void onRefresh();
    /**
     * onFinish
     */
    public abstract void onFinish();

    public void setState(RefreshState state) {
        this.mState = state;
    }

    public RefreshState getState() {
        return mState;
    }
}
